import gradio as gr

#对应inputs
def greet(name,sex,age,jj):

    salutation="恶臭男" if sex=='男' else "下头女"

    res=f"你好,{'鸡鸡'+str(jj-5)+'厘米' if sex=='男' else str(age+5)+'高寿'}的{salutation}:{name}"

    #返回值对应 outputs的列表
    return res


with gr.Blocks(title="北大村信息统计") as demo:
    gr.Markdown("# 个人信息展示器")
    with gr.Row():
        name = gr.Textbox(label="姓名",placeholder="输入名字")
        sex = gr.Radio(["男", "女"], label="性别", value="男")
    age = gr.Slider(1, 120, label="年龄", value=30)
    # 身高输入框默认隐藏，只有当性别为男时显示
    jj  = gr.Slider(5, 20, label="长度(cm)", value=5, visible=True)
    output = gr.Textbox(label="结果")
    submit_btn = gr.Button("提交")

    # 性别变化时控制长度输入框的显示状态
    def change_sex(sex):
        return gr.update(visible=(sex=='男'))
    sex.change(fn=change_sex,inputs=sex,outputs=jj)
    #绑定提交按钮
    submit_btn.click(fn=greet,inputs=[name,sex,age,jj],outputs=output)

demo.launch(share=True)